<?php
$dirList = explode ( '/', $_SERVER ['PHP_SELF'] );
$document_root = $_SERVER ["DOCUMENT_ROOT"];
require "$document_root/$dirList[1]/conf/conf.php";
$connMgr = new ConnManger ( $db_conf, $mem_conf );
$connMng = $connMgr->getConn_renren_nuo();

$page_groupId = GROUP_ADMIN_MNG;
$page_pageId = PAGE_ADMIN_ADD;
require "$document_root/$dirList[1]/mng/view/framepages/moudle_base.php";

$mode = $_POST['mode'];
$result = "normal";
if($mode == 'adminAdd'){
        $admin_id = $_POST['admin_id'];
        $admin_name = $_POST['admin_name'];
        $admin_password = $_POST['admin_password'];
        $admin_user_page = $_POST['super_user_page'];

        $rrn_admin_user = new Rrn_admin_user(array());
        $rrn_admin_user->setId("$admin_id");
        $rrn_admin_user->setName("$admin_name");
        $rrn_admin_user->setPassword("$admin_password");
        $rrn_admin_user->setPage(implode(",",$admin_user_page));
        $rrn_admin_user->setState("1");
        Rrn_admin_user_DAO::insert($rrn_admin_user,$connMng);

        $result = "succ_add";
}
?>
<div class="main-content">
        <div class="row">
                <form id="tab" method="post" action="" onSubmit="javascript:return window.confirm('确认提交吗？')">
                        <div class="col-md-4">
                                <input type="hidden" name="mode" id="mode" value='adminAdd'>

                                <div class="panel panel-default">
                                        <p class="panel-heading">操作提示：</p>
                                        <div class="panel-body">
                                                1：<span style="color:red;">&nbsp;*&nbsp;</span>的条目是给予用户的权限，请认真填写<br><br>
                                        </div>
                                </div>

                                <div class="form-group">
                                        <label for="admin_id">用户ID：</label>
                                        <input type="text" class="form-control span12" name="admin_id" id="admin_id">

                                </div>

                                <div class="form-group">
                                        <label for="admin_name">用户名称：</label>
                                        <input type="text" class="form-control span12" name="admin_name" id="admin_name">
                                </div>

                                <div class="form-group">
                                        <label for="admin_password">用户密码：</label>
                                        <input type="text" class="form-control span12" name="admin_password" id="admin_password" value="000000">
                                </div>

                                <div class="btn-toolbar list-toolbar">
                                        <input type="submit" class="btn btn-danger" value="提交">
                                </div>
                        </div>

                        <div class="col-md-4">
                                <div class="form-group">
                                        <label>权限设置：</label>
                                        <?php
                                        $group_list = Rrn_mng_group_mst_DAO::getList($connMng);
                                        $n=0;
                                        foreach ( $group_list as $group ) {
                                                $n=0;
                                                $group_id = $group->getGroupid();

                                                $page_list = Rrn_mng_page_mst_DAO::getList($group_id, $connMng);
                                                $group_name = $group->getGroupname();
                                                echo "<br> ".$group_name. " : </br>";
                                                foreach ($page_list as $page){
                                                        $n=$n+1;
                                                        if($n>3){
                                                                echo "<br>";
                                                                $n=1;
                                                        }
                                                        $page_id = $page->getPageid();
                                                        $page_name = $page->getPagename();
                                                        echo "<input type='checkbox' name= 'super_user_page[]' id='" . $page_id . "' value='$page_id'>&nbsp;$page_name&nbsp;&nbsp;&nbsp;";
                                                }

                                        }
                                        ?>
                                </div>
                        </div>
                </form>
        </div>
</div>

<script src="../lib/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript">
        function init(){
                var msg = "<?php echo $result;?>";
                if(msg == "succ_add"){
                        alert("添加管理员成功！");
                }
        }
</script>

